//Erik Wright
/*
This file describes an evolutionary algorithm that is intended to 
evolve motions in a robotic marionette.  Given that that marionette uses
the ssc-32 servo controller from Lynxmotion.
*/

#include "marionette.h"
#include <iostream>
using namespace std;


#define NUM_CONTROLLERS 6 	//breaks for even numbers... ... ... wierd...
#define MOTION_LEN 5


int main()
{
	marionette_control* motion_a = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
	marionette_control* motion_b = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
	marionette_control* motion_c = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);

	int exit = 0;
	while(!exit)
	{
		cout<<"Would you like to Exit? 1 = yes, 0 = no"<<endl;
		cin>>exit;
		if(!exit)
		{
			continue;
		}
	
		
		motion_a->display_sequence();
		motion_a->give_rating();
		
		motion_b->display_sequence();
		motion_b->give_rating();

		motion_c->display_sequence();
		motion_c->give_rating();

		if(motion_a->get_rating() > motion_b->get_rating())
		{
			if(motion_b->get_rating() > motion_c->get_rating())
			{
				delete motion_c;
				motion_c = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
				motion_a->binary_twist_rand(motion_b,1);
			}
			else
			{
				delete motion_b;
				motion_b = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
				motion_a->binary_twist_rand(motion_c,1);
			}
		}
		else
		{
			if(motion_c->get_rating() > motion_b->get_rating())
			{
				delete motion_a;
				motion_a = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
				motion_c->binary_twist_rand(motion_b,1);
			}
			else
			{
				delete motion_c;
				motion_c = new marionette_control(NUM_CONTROLLERS, MOTION_LEN);
				motion_b->binary_twist_rand(motion_a,1);
			}
		}
	}
}
				
		

